package com.wolfheader.wolfgame.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * Interceptor - 游戏令牌
 * 
 * @author 8615 Team
 * @version 1.0
 */
public class GameInterceptor extends HandlerInterceptorAdapter {

	/** "令牌"参数名称 */
	public static final String TOKEN_PARAMETER_NAME = "game_token";

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		String ua = request.getHeader("user-agent").toLowerCase();
		if (ua.indexOf("micromessenger") > 0) {// 是微信浏览器
			return true;
		}
		response.sendError(HttpServletResponse.SC_FORBIDDEN, "请使用微信浏览器");
		// String gameToken = request.getParameter("game_token");
		// if (!StringUtils.isNotBlank(gameToken)) {
		// response.sendError(HttpServletResponse.SC_FORBIDDEN, "Bad Or Missing
		// Game_Token");
		// return false;
		// }
		// String valiedateKey = MD5Utils.getMD5(request.getRemoteAddr()) +
		// MD5Utils.getMD5(gameToken);
		// String token = (String)
		// request.getSession().getAttribute(TOKEN_PARAMETER_NAME);
		// if (StringUtils.isNotBlank(token) &&
		// StringUtils.isNotBlank(gameToken) && token.equals(valiedateKey)) {
		// return true;
		// }
		// response.sendError(HttpServletResponse.SC_FORBIDDEN, "Bad Or Missing
		// Game_Token");
		return false;
	}
}
